package com.ruoyi.system.controller;

import com.ruoyi.system.domain.SysSupplier;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.service.ISysSupplierService;

/**
 * 供应商模拟 提供者
 *
 * @author ygx
 * @date 2020-06-18
 */
@RestController
@RequestMapping("sysSupplier")
public class SysSupplierController extends BaseController
{

	@Autowired
	private ISysSupplierService sysSupplierService;

	/**
	 * 查询${tableComment}
	 */
	@GetMapping("/get/{supplierId}")
	public SysSupplier get(@PathVariable("supplierId") Long supplierId)
	{
		return sysSupplierService.selectSysSupplierById(supplierId);

	}

	/**
	 * 查询供应商模拟列表
	 */
	@GetMapping("/list")
	public R list(SysSupplier sysSupplier)
	{
		startPage();
        return result(sysSupplierService.selectSysSupplierList(sysSupplier));
	}

	/**
     * 查询所有供应商
     *
     * @return 供应商列表
     */
	@GetMapping("/all")
	public R all() {
		return R.ok().put("rows",sysSupplierService.selectSupplierAll());
	}

	/**
	 * 模糊查询供应商
	 *
	 * @return 供应商列表
	 */
	@GetMapping("/search")
	public R searchSupplier(String supplierName) {
		SysSupplier sysSupplier = new SysSupplier();
		sysSupplier.setSupplierName(supplierName);
		return R.ok().put("rows",sysSupplierService.selectSysSupplierList(sysSupplier));
	}

	@GetMapping("/searchsupplier")
	public R searchSupplierbyFactoryCode(SysSupplier sysSupplier) {
		return R.ok().put("rows",sysSupplierService.selectSysFactorySupplierList(sysSupplier));
	}


    /**
     * 根据用户ID查询供应商
     *
     * @param userId 用户ID
     * @return 角色列表
     */
	@GetMapping("/getSuppliersByUserId")
    public R getSuppliersByuserId()
    {
    	    return jacResult(sysSupplierService.selectSuppliersByUserId());
    };

    /**
     * 根据用户ID查询供应商
     *
     * @param userId 用户ID
     * @return 角色列表
     */
	@GetMapping("getSuppliersByUserId/{userId}")
    public R getSuppliers(@PathVariable("userId") Long userId)
    {
    	    return jacResult(sysSupplierService.selectSuppliersByUserId(userId));
    };


	/**
	 * 新增保存供应商模拟
	 */
	@PostMapping("save")
	public R addSave(@RequestBody SysSupplier sysSupplier)
	{
		return toAjax(sysSupplierService.insertSysSupplier(sysSupplier));
	}

	/**
	 * 修改保存供应商模拟
	 */
	@PostMapping("update")
	public R editSave(@RequestBody SysSupplier sysSupplier)
	{
		return toAjax(sysSupplierService.updateSysSupplier(sysSupplier));
	}

	/**
	 * 删除${tableComment}
	 */
	@PostMapping("remove")
	public R remove(String ids)
	{
		return toAjax(sysSupplierService.deleteSysSupplierByIds(ids));
	}



}
